<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>utc() | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>utc()</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>utc()</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/parsing/utc/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/01-parsing/13-utc.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment.utc();
moment.utc(Number);
moment.utc(Number[]);
moment.utc(String);
moment.utc(String, String);
moment.utc(String, String[]);
moment.utc(String, String, String);
moment.utc(String, String, Boolean);
moment.utc(String, String, String, Boolean);
moment.utc(Moment);
moment.utc(Date);
</code></pre>

							</div>
<p>&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;moment &#x4F1A;&#x89E3;&#x6790;&#x5E76;&#x4EE5;&#x672C;&#x5730;&#x65F6;&#x95F4;&#x663E;&#x793A;&#x3002;</p>
<p>&#x5982;&#x679C;&#x8981;&#x89E3;&#x6790;&#x6216;&#x4EE5; UTC &#x663E;&#x793A; moment&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>moment.utc()</code> &#x800C;&#x4E0D;&#x662F; <code>moment()</code>&#x3002;</p>
<p>&#x8FD9;&#x4E3A;&#x6211;&#x4EEC;&#x5E26;&#x6765;&#x4E86; Moment.js &#x7684;&#x6709;&#x8DA3;&#x7684;&#x7279;&#x6027;&#x3002;
UTC &#x6A21;&#x5F0F;&#x3002;</p>
<p>&#x5728; UTC &#x6A21;&#x5F0F;&#x4E2D;&#xFF0C;&#x6240;&#x6709;&#x7684;&#x663E;&#x793A;&#x65B9;&#x6CD5;&#x90FD;&#x5C06;&#x4F1A;&#x4EE5; UTC &#x65F6;&#x95F4;&#xFF08;&#x800C;&#x975E;&#x672C;&#x5730;&#x65F6;&#x95F4;&#xFF09;&#x663E;&#x793A;&#x3002;</p>
<pre><code class="language-javascript">moment().format();     // 2013-02-04T10:35:24-08:00
moment.utc().format(); // 2013-02-04T18:35:24+00:00
</code></pre>
<p>&#x6B64;&#x5916;&#xFF0C;&#x5728; UTC &#x6A21;&#x5F0F;&#x4E2D;&#xFF0C;&#x6240;&#x6709;&#x7684; getter &#x548C; setter &#x90FD;&#x5C06;&#x4F1A;&#x5728;&#x5185;&#x90E8;&#x4F7F;&#x7528; <code>Date#getUTC*</code> &#x548C; <code>Date#setUTC*</code> &#x65B9;&#x6CD5;&#xFF0C;&#x800C;&#x4E0D;&#x662F; <code>Date#get*</code> &#x548C; <code>Date#set*</code> &#x65B9;&#x6CD5;&#x3002;</p>
<pre><code class="language-javascript">moment.utc().seconds(30).valueOf() === new Date().setUTCSeconds(30);
moment.utc().seconds()   === new Date().getUTCSeconds();
</code></pre>
<p>&#x91CD;&#x8981;&#x7684;&#x662F;&#x8981;&#x6CE8;&#x610F;&#xFF0C;&#x5C3D;&#x7BA1;&#x4E0A;&#x9762;&#x7684;&#x663E;&#x793A;&#x6709;&#x6240;&#x4E0D;&#x540C;&#xFF0C;&#x4F46;&#x5B83;&#x4EEC;&#x5728;&#x540C;&#x4E00;&#x65F6;&#x95F4;&#x90FD;&#x662F;&#x76F8;&#x540C;&#x7684; moment&#x3002;</p>
<pre><code class="language-javascript">var a = moment();
var b = moment.utc();
a.format();  // 2013-02-04T10:35:24-08:00
b.format();  // 2013-02-04T18:35:24+00:00
a.valueOf(); // 1360002924000
b.valueOf(); // 1360002924000
</code></pre>
<p>&#x4F7F;&#x7528; <code>moment.utc()</code> &#x521B;&#x5EFA;&#x7684;&#x4EFB;&#x4F55; moment &#x90FD;&#x5C06;&#x4F1A;&#x5904;&#x4E8E; UTC &#x6A21;&#x5F0F;&#x4E2D;&#xFF0C;&#x800C;&#x4F7F;&#x7528; <code>moment()</code> &#x521B;&#x5EFA;&#x7684;&#x4EFB;&#x4F55; moment &#x5219;&#x4E0D;&#x4F1A;&#x3002;</p>
<p>&#x82E5;&#x8981;&#x4ECE; UTC &#x5207;&#x6362;&#x5230;&#x672C;&#x5730;&#x65F6;&#x95F4;&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <a href="javascript:window.open('http://nodejs.cn/s/t4J2Y4');" target="_blank" rel="nofollow">moment#utc</a> &#x6216; <a href="javascript:window.open('http://nodejs.cn/s/NJfxxZ');" target="_blank" rel="nofollow">moment#local</a>&#x3002;</p>
<pre><code class="language-javascript">var a = moment.utc([2011, 0, 1, 8]);
a.hours(); // 8 UTC
a.local();
a.hours(); // 0 PST
</code></pre>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment.utc();
moment.utc(Number);
moment.utc(Number[]);
moment.utc(String);
moment.utc(String, String);
moment.utc(String, String[]);
moment.utc(String, String, String);
moment.utc(String, String, Boolean);
moment.utc(String, String, String, Boolean);
moment.utc(Moment);
moment.utc(Date);
</code></pre>

							</div>
<p>By default, moment parses and displays in local time.</p>
<p>If you want to parse or display a moment in UTC, you can use <code>moment.utc()</code> instead of <code>moment()</code>.</p>
<p>This brings us to an interesting feature of Moment.js. UTC mode.</p>
<p>While in UTC mode, all display methods will display in UTC time instead of local time.</p>
<pre><code class="language-javascript">moment().format();     // 2013-02-04T10:35:24-08:00
moment.utc().format(); // 2013-02-04T18:35:24+00:00
</code></pre>
<p>Additionally, while in UTC mode, all getters and setters will internally use the <code>Date#getUTC*</code> and <code>Date#setUTC*</code> methods instead of the <code>Date#get*</code> and <code>Date#set*</code> methods.</p>
<pre><code class="language-javascript">moment.utc().seconds(30).valueOf() === new Date().setUTCSeconds(30);
moment.utc().seconds()   === new Date().getUTCSeconds();
</code></pre>
<p>It is important to note that though the displays differ above, they are both the same moment in time.</p>
<pre><code class="language-javascript">var a = moment();
var b = moment.utc();
a.format();  // 2013-02-04T10:35:24-08:00
b.format();  // 2013-02-04T18:35:24+00:00
a.valueOf(); // 1360002924000
b.valueOf(); // 1360002924000
</code></pre>
<p>Any moment created with <code>moment.utc()</code> will be in UTC mode, and any moment created with <code>moment()</code> will not.</p>
<p>To switch from UTC to local time, you can use <a href="#/manipulating/utc/" target="_blank" rel="nofollow">moment#utc</a> or <a href="#/manipulating/local/" target="_blank" rel="nofollow">moment#local</a>.</p>
<pre><code class="language-javascript">var a = moment.utc([2011, 0, 1, 8]);
a.hours(); // 8 UTC
a.local();
a.hours(); // 0 PST
</code></pre>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>